<template>
  <div class="hm_user">
    <div class="pic">
      <img :src="avatar" alt="" />
      <h3>{{ username }}</h3>
    </div>
    <van-grid clickable :column-num="3" :border="false">
      <van-grid-item icon="clock-o" text="历史记录" to="/" />
      <van-grid-item icon="bookmark-o" text="我的收藏" to="/collect" />
      <van-grid-item icon="thumb-circle-o" text="我的点赞" to="/like" />
    </van-grid>

    <van-cell-group class="listItem">
      <van-cell title="推荐分享" is-link />
      <van-cell title="意见反馈" is-link />
      <van-cell title="关于我们" is-link />
      <van-cell @click="logout" title="退出登录" is-link />
    </van-cell-group>
  </div>
</template>

<script>
import { removeToken } from "@/utils/tokens";
import { getUserInfo } from "@/api/user";
export default {
  name: "HmUser",
  data() {
    return {
      username: "",
      avatar: "",
    };
  },
  created() {
    getUserInfo().then((res) => {
      this.username = res.data.username;
      this.avatar = res.data.avatar;
    });
  },
  methods: {
    logout() {
      console.log("退出登录");
      removeToken();
      this.$router.push("/login");
      this.$toast.success("退出成功");
    },
  },
};
</script>

<style lang="less" scoped>
.hm_user {
  padding: 0 10px;
  background: #f5f5f5;
  height: 100%;

  .pic {
    display: flex;
    padding: 20px 0;
    align-items: center;
    img {
      width: 50px;
      height: 50px;
      border-radius: 50%;
      overflow: hidden;
    }
    h3 {
      padding-left: 20px;
      font-size: 18px;
    }
  }
  .listItem {
    margin-top: 20px;
  }
}
</style>
